home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / amiga-magazin-pd / 03-95-2 / datatypes / beispiel4.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  4KB  |  214 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <graphics/gfxbase.h>
  3. #include <datatypes/pictureclass.h>
  4. #include <exec/memory.h>
  5.  
  6. #include <clib/datatypes_protos.h>
  7. #include <clib/intuition_protos.h>
  8. #include <clib/graphics_protos.h>
  9. #include <clib/alib_protos.h>
  10. #include <clib/exec_protos.h>
  11. #include <clib/macros.h>
  12.  
  13. #include <stdio.h>
  14.  
  15. struct IntuitionBase    *IntuitionBase;
  16. struct GfxBase            *GfxBase;
  17. struct Library            *DataTypesBase;
  18.  
  19. VOID                    CloseAll(VOID);
  20. BOOL                    OpenAll(VOID);
  21. VOID                    PrintPicture(Object *Picture);
  22. Object *                GetPicture(VOID);
  23.  
  24. int
  25. main(int argc,char **argv)
  26. {
  27.     int Result = RETURN_FAIL;
  28.  
  29.     if(OpenAll())
  30.     {
  31.         Object *Picture;
  32.  
  33.         Result = RETURN_OK;
  34.  
  35.         if(Picture = GetPicture())
  36.         {
  37.             printf("Vorderster Bildschirm wird gedruckt.\n");
  38.  
  39.             PrintPicture(Picture);
  40.         }
  41.     }
  42.  
  43.     CloseAll();
  44.  
  45.     return(Result);
  46. }
  47.  
  48. VOID
  49. CloseAll()
  50. {
  51.     CloseLibrary((struct Library *)IntuitionBase);
  52.     CloseLibrary((struct Library *)GfxBase);
  53.     CloseLibrary(DataTypesBase);
  54. }
  55.  
  56. BOOL
  57. OpenAll()
  58. {
  59.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",
  60.         39)))
  61.     {
  62.         printf("Kann intuition.library v39 nicht öffnen\n");
  63.         return(FALSE);
  64.     }
  65.  
  66.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
  67.     {
  68.         printf("Kann graphics.library v39 nicht öffnen\n");
  69.         return(FALSE);
  70.     }
  71.  
  72.     if(!(DataTypesBase = OpenLibrary("datatypes.library",39)))
  73.     {
  74.         printf("Kann datatypes.library v39 nicht öffnen\n");
  75.         return(FALSE);
  76.     }
  77.  
  78.     return(TRUE);
  79. }
  80.  
  81. VOID
  82. PrintPicture(Object *Picture)
  83. {
  84.     struct MsgPort *PrinterPort;
  85.  
  86.     if(PrinterPort = CreateMsgPort())
  87.     {
  88.         union printerIO *PrinterIO;
  89.  
  90.         if(PrinterIO = (union printerIO *)CreateIORequest(PrinterPort,
  91.             sizeof(union printerIO)))
  92.         {
  93.             if(!OpenDevice("printer.device",0,(struct IORequest *)PrinterIO,
  94.                 NULL))
  95.             {
  96.                 DoMethod(Picture,DTM_PRINT,NULL,PrinterIO,NULL);
  97.  
  98.                 CloseDevice((struct IORequest *)PrinterIO);
  99.             }
  100.  
  101.             DeleteIORequest((struct IORequest *)PrinterIO);
  102.         }
  103.  
  104.         DeleteMsgPort(PrinterPort);
  105.     }
  106.  
  107.     DisposeDTObject(Picture);
  108. }
  109.  
  110. Object *
  111. GetPicture()
  112. {
  113.     struct BitMap    *BitMap;
  114.     ULONG             IntuiLock;
  115.     struct RastPort    *RPort;
  116.     struct Screen    *Screen;
  117.     LONG             PageWidth,PageHeight,
  118.                      Depth;
  119.     BOOL             Locked = TRUE;
  120.  
  121.     IntuiLock    = LockIBase(NULL);
  122.  
  123.     Screen        = IntuitionBase -> FirstScreen;
  124.     RPort        = &Screen -> RastPort;
  125.  
  126.     PageWidth    = Screen -> Width;
  127.     PageHeight    = Screen -> Height;
  128.     Depth        = GetBitMapAttr(RPort -> BitMap,BMA_DEPTH);
  129.  
  130.     if(BitMap = AllocBitMap(PageWidth,PageHeight,Depth,BMF_CLEAR,
  131.         RPort -> BitMap))
  132.     {
  133.         ULONG    *ColourTable,
  134.                  ModeID;
  135.         LONG     NumColours = Screen -> ViewPort . ColorMap -> Count;
  136.  
  137.         ModeID = GetVPModeID(&Screen -> ViewPort);
  138.  
  139.         BltBitMap(RPort -> BitMap,0,0,BitMap,0,0,PageWidth,PageHeight,0xC0,
  140.             0xFF,NULL);
  141.  
  142.         WaitBlit();
  143.  
  144.         if(ColourTable = (ULONG *)AllocVec(sizeof(ULONG) * 3 * NumColours,
  145.             MEMF_ANY))
  146.         {
  147.             Object *Picture;
  148.  
  149.             GetRGB32(Screen -> ViewPort . ColorMap,0,NumColours,ColourTable);
  150.  
  151.             UnlockIBase(IntuiLock);
  152.  
  153.             Locked = FALSE;
  154.  
  155.             if(Picture = NewDTObject("FirstScreen",
  156.                 DTA_SourceType,    DTST_RAM,
  157.                 DTA_GroupID,    GID_PICTURE,
  158.                 PDTA_NumColors,    NumColours,
  159.                 PDTA_BitMap,    BitMap,
  160.                 PDTA_ModeID,    ModeID,
  161.             TAG_DONE))
  162.             {
  163.                 struct ColorRegister    *ColourMap;
  164.                 struct BitMapHeader        *BitMapHeader;
  165.                 ULONG                    *Colours;
  166.     
  167.                 if(GetDTAttrs(Picture,
  168.                     PDTA_BitMapHeader,    &BitMapHeader,
  169.                     PDTA_ColorRegisters,&ColourMap,
  170.                     PDTA_CRegs,            &Colours,
  171.                 TAG_DONE) == 3)
  172.                 {
  173.                     BitMapHeader -> bmh_Left        = 0;
  174.                     BitMapHeader -> bmh_Top            = 0;
  175.                     BitMapHeader -> bmh_Width        = PageWidth;
  176.                     BitMapHeader -> bmh_Height        = PageHeight;
  177.                     BitMapHeader -> bmh_Depth        = Depth;
  178.                     BitMapHeader -> bmh_PageWidth    = PageWidth;
  179.                     BitMapHeader -> bmh_PageHeight    = PageHeight;
  180.  
  181.                     CopyMem(ColourTable,Colours,
  182.                         3 * sizeof(ULONG) * NumColours);
  183.     
  184.                     while(NumColours--)
  185.                     {
  186.                         ColourMap -> red    = (UBYTE)((*Colours++) >> 24);
  187.                         ColourMap -> green    = (UBYTE)((*Colours++) >> 24);
  188.                         ColourMap -> blue    = (UBYTE)((*Colours++) >> 24);
  189.  
  190.                         ColourMap++;
  191.                     }
  192.  
  193.                     FreeVec(ColourTable);
  194.  
  195.                     return(Picture);
  196.                 }
  197.  
  198.                 DisposeDTObject(Picture);
  199.  
  200.                 BitMap = NULL;
  201.             }
  202.  
  203.             FreeVec(ColourTable);
  204.         }
  205.  
  206.         FreeBitMap(BitMap);
  207.     }
  208.  
  209.     if(Locked)
  210.         UnlockIBase(IntuiLock);
  211.  
  212.     return(NULL);
  213. }
  214.